package com.ywl.designpattern.prototype.deepclone;

public class DeepCloneDemo {
    public static void main(String[] args) {
        CarCache.loadCache();

        Car originalCar = CarCache.getCar("1");
        Car clonedCar = CarCache.getCar("1");

        System.out.println("Original Car: " + originalCar);
        System.out.println("Cloned Car: " + clonedCar);

        // 验证深克隆
        System.out.println("\nChanging cloned car's engine type...");
        clonedCar.getEngine().setType("Modified Electric");

        System.out.println("\nAfter modification:");
        System.out.println("Original Car: " + originalCar);
        System.out.println("Cloned Car: " + clonedCar);

        // 验证不同实例
        System.out.println("\nAre car instances the same? " + (originalCar == clonedCar));
        System.out.println("Are engine instances the same? " + (originalCar.getEngine() == clonedCar.getEngine()));
    }
}

